<template>
	<view class="page">
		<view class="user-info">
			<view class="border-outer">
				<view class="border-inner">
					<image :src="avater" mode="widthFix" class="photo" :lazy-load="true"></image>
				</view>
			</view>
			<view class="summary">
				<view>
					<text class="title">姓名</text>
					<text class="value">{{name}}</text>
				</view>
				<view>
					<text class="title">职级</text>
					<text class="value">{{role}}</text>
				</view>
				<view>
					<text class="title">状态</text>
					<text class="value">{{status}}</text>
				</view>
			</view>
		</view>
		<view class="list-title">
			用户信息栏目
		</view>
		<uni-list>
			<uni-list-item title="个人信息" link to="/pages/user_info/user_info"></uni-list-item>
		</uni-list>
		<view class="list-title">
			系统管理栏目
		</view>
		<uni-list>
			<uni-list-item title="设置" link to="/pages/settings/settings"></uni-list-item>
			<uni-list-item title="退出登录" clickable="true" @click="loginout()"></uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	import uniList from '@/components/uni-list/uni-list.vue';
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
	export default {
		components: {
			uniList,
			uniListItem,
		},
		data() {
			return {
				name: '',
				role: '',
				avater: '',
				status:'出勤'
			}
		},
		onShow: function() {
			let that = this;
			that.ajax(that.url.getuserinfo, "POST", null, function(resp) {
				let data = resp.data;
				let user = data.userinfo.user;
				if(!user.isRegistration||user.name==null || user.name.length<=0){
					that.name = "新员工"
				}else{
					that.name = user.name;
				}
				if(!user.isRegistration||user.avater == null || user.avater.length<=0){
					that.avater = "../../static/default-avater.jpg"
				}else{
					that.avater = user.avater;
				}
				let roles = data.userinfo.roles;
				that.role = roles[0].name;
			});
			//TODO 状态显示
		},
		methods: {
			loginout:function(){
				let that = this;
				uni.showModal({
					title:"提示",
					content:"是否退出登录，退出登录后需要重新登录",
					success:function(e){
						if(e.confirm){
							that.ajax(that.url.loginout, 'POST', this.loginForm, function(resp){
								let data = resp.data;
								if(data.code==20000){
									//去除本地token
									uni.removeStorageSync("token");
									//清除本地缓存
									uni.clearStorageSync();
								}
							});
							uni.showLoading({
								title:"正在退出"
							});
							setTimeout(function(){
								uni.hideLoading();
								uni.redirectTo({
									url:'../login/login'
								})
							},2000);
						}
					}
				})
			}
		}
	}
</script>

<style lang="less">
	@import url("mine.less");
</style>
